package com.yboot.starter.shiro.config;

import com.yboot.starter.shiro.core.impl.ShiroUserDetailService;
import com.yboot.starter.shiro.core.impl.DefaultShiroUserDetailServiceImpl;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 功能描述
 *
 * @author yangcs
 * @date 2025/8/19
 */
@Configuration
public class ShiroMissBeanConfig {

    @Bean
    @ConditionalOnMissingBean
    public ShiroUserDetailService shiroUserDetailService() {
        return new DefaultShiroUserDetailServiceImpl();
    }
    @Bean
    @ConditionalOnMissingBean
    public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
        DefaultAdvisorAutoProxyCreator creator = new DefaultAdvisorAutoProxyCreator();
        creator.setProxyTargetClass(true);
        // 强制使用CGLIB代理
        return creator;
    }

    @Bean
    @ConditionalOnMissingBean
    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
        AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
        advisor.setSecurityManager(securityManager);
        return advisor;
    }

}
